	*------------------------------------------------------------------------------------------------------------%	
	* Figure D11: Bunching analysis of own wage effects, large retailer VMWs
	*------------------------------------------------------------------------------------------------------------%	

	* Own effects ------------------------------------------------------------------

	foreach length in 5 {

		* Load own policy firm data
		if `length' == 23 {
			use "$data/cb/stacked_policy_firm_dataset_long.dta", clear
		}
		else {
			use "$data/cb/stacked_policy_firm_dataset.dta", clear
		}
		
		keep if months_until > `length'
		
		* Restrict to experiment window
		keep if inrange(etime,-6, `length')
		drop if trt_exp==4
		
		* Balance
		if `length' == 5 {
			local balance balanced_short
		}
		else if `length' == 11 {
			local balance balanced_long
		}
		if `length' == 23 {
			local balance balanced_6_23
		}
		
		* Indicator for post policy
		gen postperiod = etime>=0

		
		* Generate relative wage share
		foreach i of numlist 10/1 {
			gen share_relwage_m`i' = .
		}
		foreach i of numlist 0/20 {
			gen share_relwage_`i' = .
		}
		levelsof mw, local(mws)
		foreach mw in `mws' {
			foreach i of numlist 0/20 {
				local n = `mw' + `i'
				if `n' < 30 {
					replace share_relwage_`i' = share_wage_`n' if mw == `mw'
				}
			}
			foreach i of numlist 10/1 {
				local n = `mw' - `i'
				if `n' > 6 {
					replace share_relwage_m`i' = share_wage_`n' if mw == `mw'
				}
			}
		}
		
		
		* Regress
		eststo clear
		
		* All
		preserve
		
		* Sample restrictions
		keep if `balance' == 1
		
		* Generate treatment variable
		egen T_std=std(T)
		gen D = T_std*postperiod
		
		matrix b = . , . , .
		foreach num of numlist 10/1 {
			count if `balance' == 1 & !missing(share_relwage_m`num')
			if `r(N)' > 0 {
				reghdfe share_relwage_m`num' D if `balance' == 1, absorb(i.etime#i.trt_exp i.cz#i.trt_exp i.cz i.etime i.trt_exp) cluster(cz)
				local i = -`num'
				matrix b = b \ `i', _b[D], _se[D]
			}
		}
		foreach num of numlist 0/20 {
			count if `balance' == 1 & !missing(share_relwage_`num')
			if `r(N)' > 0 {
				reghdfe share_relwage_`num' D if `balance' == 1, absorb(i.etime#i.trt_exp i.cz#i.trt_exp i.cz i.etime i.trt_exp) cluster(cz)
				local i = `num'
				matrix b = b \ `i', _b[D], _se[D]
			}
		}
		matlist b
		restore
		
		preserve
			clear
			svmat b
			drop in 1
			
			rename *1 mw_dif
			rename *2 b
			rename *3 se
			gen lb = b - 1.96*se
			gen ub = b + 1.96*se
			
			graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on share in wage bin")
			graph export "$figures_tables/appendix/figd11a_bunching_effects_all_`length'.pdf", replace


		restore
		
		* Major
		preserve
		
		* Sample restrictions
		keep if `balance' == 1 & share_affected > .3
		
		* Generate treatment variable
		egen T_std=std(T)
		gen D = T_std*postperiod
		
		matrix b = . , . , .
		foreach num of numlist 10/1 {
			count if `balance' == 1 & share_affected > .3 & !missing(share_relwage_m`num')
			if `r(N)' > 0 {
				reghdfe share_relwage_m`num' D if `balance' == 1 & share_affected > .3, absorb(i.etime#i.trt_exp i.cz#i.trt_exp i.cz i.etime i.trt_exp) cluster(cz)
				local i = -`num'
				matrix b = b \ `i', _b[D], _se[D]
			}
		}
		foreach num of numlist 0/20 {
			count if `balance' == 1 & share_affected > .3 & !missing(share_relwage_`num')
			if `r(N)' > 0 {
				reghdfe share_relwage_`num' D if `balance' == 1 & share_affected > .3, absorb(i.etime#i.trt_exp i.cz#i.trt_exp i.cz i.etime i.trt_exp) cluster(cz)
				local i = `num'
				matrix b = b \ `i', _b[D], _se[D]
			}
		}
		matlist b
		restore
		
		preserve
			clear
			svmat b
			drop in 1
			
			rename *1 mw_dif
			rename *2 b
			rename *3 se
			gen lb = b - 1.96*se
			gen ub = b + 1.96*se
			
			graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on share in wage bin")
			graph export "$figures_tables/appendix/figd11b_bunching_effects_major_`length'.pdf", replace

		restore
		
		* $15
		preserve
		
		* Sample restrictions
		keep if `balance' == 1 & mw == 15
		
		* Generate treatment variable
		egen T_std=std(T)
		gen D = T_std*postperiod
		
		matrix b = . , . , .
		foreach num of numlist 10/1 {
			count if `balance' == 1 & mw == 15  & !missing(share_relwage_m`num')
			if `r(N)' > 0 {
				reghdfe share_relwage_m`num' D if `balance' == 1 & mw == 15, absorb(i.etime#i.trt_exp i.cz#i.trt_exp i.cz i.etime i.trt_exp) cluster(cz)
				local i = -`num'
				matrix b = b \ `i', _b[D], _se[D]
			}
		}
		foreach num of numlist 0/20 {
			count if `balance' == 1 & mw == 15  & !missing(share_relwage_`num')
			if `r(N)' > 0 {
				reghdfe share_relwage_`num' D if `balance' == 1 & mw == 15, absorb(i.etime#i.trt_exp i.cz#i.trt_exp i.cz i.etime i.trt_exp) cluster(cz)
				local i = `num'
				matrix b = b \ `i', _b[D], _se[D]
			}
		}
		matlist b
		restore 
		
		preserve
			clear
			svmat b
			drop in 1
			
			rename *1 mw_dif
			rename *2 b
			rename *3 se
			gen lb = b - 1.96*se
			gen ub = b + 1.96*se
			
			graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on share in wage bin")
			graph export "$figures_tables/appendix/figd11c_bunching_effects_15_`length'.pdf", replace
			
		restore
		
	}

*------------------------------------------------------------------------------------------------------------%	
* Figure D12: Bunching analysis of spillover wage effects, large retailer gap
*------------------------------------------------------------------------------------------------------------%	
	
* Spillover effects ------------------------------------------------------------

foreach length in 11 {

	* Load own policy firm data
	if `length' == 23 {
		use if inrange(etime,-6, `length') & trt_exp!=4 & months_until > `length' & balanced_short==1 using "$data/cb/stacked_nonpolicy_firm_dataset_long.dta", clear
	}
	else {
		use if inrange(etime,-6, `length') & trt_exp!=4 & months_until > `length' & balanced_short==1  using "$data/cb/stacked_nonpolicy_firm_dataset.dta", clear
	}
	
	* Balance
	if `length' == 5 {
		local balance balanced_short
	}
	else if `length' == 11 {
		local balance balanced_long
	}
	if `length' == 23 {
		local balance balanced_6_23
	}
	
	* Indicator for post policy
	gen postperiod = etime>=0

	
	* Generate relative wage share
	rename share_wage_lt8 share_wage_7
	foreach i of numlist 10/1 {
		gen share_relwage_m`i' = .
	}
	foreach i of numlist 0/20 {
		gen share_relwage_`i' = .
	}
	levelsof mw, local(mws)
	foreach mw in `mws' {
		foreach i of numlist 0/20 {
			local n = `mw' + `i'
			if `n' < 30 {
				replace share_relwage_`i' = share_wage_`n' if mw == `mw'
			}
		}
		foreach i of numlist 10/1 {
			local n = `mw' - `i'
			if `n' > 6 {
				replace share_relwage_m`i' = share_wage_`n' if mw == `mw'
			}
		}
	}
	
	
	* Regress
	eststo clear
	
	* All
	preserve
	
	* Sample restrictions
	keep if `balance' == 1
	
	* Generate treatment variable
	egen T_std=std(T)
	gen D = T_std*postperiod
		
	matrix b = . , . , .
	foreach num of numlist 8/1 {
		count if `balance' == 1 & !missing(share_relwage_m`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_m`num' D if `balance' == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = -`num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	foreach num of numlist 0/20 {
		count if `balance' == 1 & !missing(share_relwage_`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_`num' D if `balance' == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = `num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	matlist b
	restore
	
	preserve
		clear
		svmat b
		drop in 1
		
		rename *1 mw_dif
		rename *2 b
		rename *3 se
		gen lb = b - 1.96*se
		gen ub = b + 1.96*se
		
		graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on employment in wage bin")
		graph export "$figures_tables/appendix/figd12a_bunching_spillover_effects_all_`length'.pdf", replace

	restore
	
	* Major
	preserve
	
	* Sample restrictions
	keep if `balance' == 1 & share_affected > .3
	
	* Generate treatment variable
	egen T_std=std(T)
	gen D = T_std*postperiod

	matrix b = . , . , .
	foreach num of numlist 10/1 {
		count if `balance' == 1 & share_affected > .3 & !missing(share_relwage_m`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_m`num' D if `balance' == 1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = -`num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	foreach num of numlist 0/20 {
		count if `balance' == 1 & share_affected > .3 & !missing(share_relwage_`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_`num' D if `balance' == 1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = `num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	matlist b
	restore 
	
	preserve
		clear
		svmat b
		drop in 1
		
		rename *1 mw_dif
		rename *2 b
		rename *3 se
		gen lb = b - 1.96*se
		gen ub = b + 1.96*se
		
		graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on employment in wage bin")
		graph export "$figures_tables/appendix/figd12b_bunching_spillover_effects_major_`length'.pdf", replace
		
	restore
	
	* $15
	preserve
	
	* Sample restrictions
	keep if `balance' == 1 & share_affected > .3
	
	* Generate treatment variable
	egen T_std=std(T)
	gen D = T_std*postperiod
	
	matrix b = . , . , .
	foreach num of numlist 10/1 {
		count if `balance' == 1 & mw == 15  & !missing(share_relwage_m`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_m`num' D if `balance' == 1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = -`num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	foreach num of numlist 0/20 {
		count if `balance' == 1 & mw == 15  & !missing(share_relwage_`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_`num' D if `balance' == 1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = `num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	matlist b
	restore
	
	preserve
		clear
		svmat b
		drop in 1
		
		rename *1 mw_dif
		rename *2 b
		rename *3 se
		gen lb = b - 1.96*se
		gen ub = b + 1.96*se
		
		graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on employment in wage bin")
		graph export "$figures_tables/appendix/figd12c_bunching_spillover_effects_15_`length'.pdf", replace
		
	restore
	
}

	*------------------------------------------------------------------------------------------------------------%	
	* Figure D13: Bunching analysis of spillover wage effects, market gap
	*------------------------------------------------------------------------------------------------------------%	

* Spillover effects ------------------------------------------------------------

foreach length in 11 {

	* Load own policy firm data
	if `length' == 23 {
		use if inrange(etime,-6, `length') & trt_exp!=4 & months_until > `length' & balanced_short==1 using "$data/cb/stacked_nonpolicy_firm_dataset_long.dta", clear
	}
	else {
		use if inrange(etime,-6, `length') & trt_exp!=4 & months_until > `length' & balanced_short==1 using "$data/cb/stacked_nonpolicy_firm_dataset.dta", clear
	}
	
	* Balance
	if `length' == 5 {
		local balance balanced_short
	}
	else if `length' == 11 {
		local balance balanced_long
	}
	if `length' == 23 {
		local balance balanced_6_23
	}
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Generate relative wage share
	rename share_wage_lt8 share_wage_7
	foreach i of numlist 10/1 {
		gen share_relwage_m`i' = .
	}
	foreach i of numlist 0/20 {
		gen share_relwage_`i' = .
	}
	levelsof mw, local(mws)
	foreach mw in `mws' {
		foreach i of numlist 0/20 {
			local n = `mw' + `i'
			if `n' < 30 {
				replace share_relwage_`i' = share_wage_`n' if mw == `mw'
			}
		}
		foreach i of numlist 10/1 {
			local n = `mw' - `i'
			if `n' > 6 {
				replace share_relwage_m`i' = share_wage_`n' if mw == `mw'
			}
		}
	}
	
	
	* Regress
	eststo clear
	
	* All
	preserve
	
	* Sample restrictions
	keep if `balance' == 1
	
	* Generate treatment variable
	egen sg_std=std(super_gap)
	
	gen D = sg_std*postperiod
	
	matrix b = . , . , .
	foreach num of numlist 8/1 {
		count if `balance' == 1 & !missing(share_relwage_m`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_m`num' D if `balance' == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = -`num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	foreach num of numlist 0/20 {
		count if `balance' == 1 & !missing(share_relwage_`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_`num' D if `balance' == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = `num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	matlist b
	restore
	
	preserve
		clear
		svmat b
		drop in 1
		
		rename *1 mw_dif
		rename *2 b
		rename *3 se
		gen lb = b - 1.96*se
		gen ub = b + 1.96*se
		
		graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on employment in wage bin")
		graph export "$figures_tables/appendix/figd13a_sg_bunching_spillover_effects_all_`length'.pdf", replace

	restore
	
	* Major
	preserve
	
	* Sample restrictions
	keep if `balance' == 1 & share_affected > .3
	
	* Generate treatment variable
	egen sg_std=std(super_gap)
	
	gen D = sg_std*postperiod
	
	matrix b = . , . , .
	foreach num of numlist 10/1 {
		count if `balance' == 1 & share_affected > .3 & !missing(share_relwage_m`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_m`num' D if `balance' == 1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = -`num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	foreach num of numlist 0/20 {
		count if `balance' == 1 & share_affected > .3 & !missing(share_relwage_`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_`num' D if `balance' == 1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = `num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	matlist b
	restore
	
	preserve
		clear
		svmat b
		drop in 1
		
		rename *1 mw_dif
		rename *2 b
		rename *3 se
		gen lb = b - 1.96*se
		gen ub = b + 1.96*se
		
		graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on employment in wage bin")
		graph export "$figures_tables/appendix/figd13b_sg_bunching_spillover_effects_major_`length'.pdf", replace

	restore
	
	* $15
	preserve
	
	* Sample restrictions
	keep if `balance' == 1 & mw == 15
	
	* Generate treatment variable
	egen sg_std=std(super_gap)
	
	gen D = sg_std*postperiod
	
	matrix b = . , . , .
	foreach num of numlist 10/1 {
		count if `balance' == 1 & mw == 15  & !missing(share_relwage_m`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_m`num' D if `balance' == 1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = -`num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	foreach num of numlist 0/20 {
		count if `balance' == 1 & mw == 15  & !missing(share_relwage_`num')
		if `r(N)' > 0 {
			reghdfe share_relwage_`num' D if `balance' == 1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
			local i = `num'
			matrix b = b \ `i', _b[D], _se[D]
		}
	}
	matlist b
	restore
	
	preserve
		clear
		svmat b
		drop in 1
		
		rename *1 mw_dif
		rename *2 b
		rename *3 se
		gen lb = b - 1.96*se
		gen ub = b + 1.96*se
		
		graph tw (bar b mw_dif, color("$dnwblue")) (rcap lb ub mw_dif, color("$dnwblue")), xline(-0.5, lpattern(solid)) yline(0, lpattern(solid)) legend(off) xtitle("Relative wage bin") ytitle("Effect on employment in wage bin")
		graph export "$figures_tables/appendix/figd13c_sg_bunching_spillover_effects_15_`length'.pdf", replace
		
	restore
	
}
